home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: need for function prototypes
- Date: 01 Mar 1996 16:10:50 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Mar1091050@qcd.lanl.gov>
- References: <31333401.7D03@stat.uni-muenchen.de> <4h56juINNmd0@anvil.ugrad.cs.ubc.ca>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: c2a192@ugrad.cs.ubc.ca's message of 29 Feb 1996 13:42:22 -0800
-
- In article <4h56juINNmd0@anvil.ugrad.cs.ubc.ca>
- c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
-
- KK: The function definition serves as a prototype, when you are ``down
- wind'' in
- KK: the scope---that is, if the function you are calling is defined before the
- KK: place where you are calling it. This is not a case of not having a
- prototype.
-
- I know what the poster meant by these statements, but technically this
- is incorrect. There are two kinds of function definitions: with and
- without prototypes. Thus
-
- char f(x) char x; {/* ... */} /* Non-prototyped definition */
- char g(char x) {/* ... */} /* Prototyped definition */
-
- The former does not serve as a prototype: After these, f(1,2) leads to
- undefined behaviour (i.e. it is wrong, but the compiler does not
- _have_ to diagnose it), whereas g(1,2) leads to a constraint violation
- which needs to be diagnosed. Note that nothing prohibits the compiler
- from diagnosing the undefined behaviour in incorrect calls to f, but
- the standard does not require the compiler to do so. Undefined
- behaviour also means that the implementation may or may not define a
- meaning for it.
-
- Furthermore, the parameter passing convention of f and g may be
- different. The implementation must behave as if f was prototyped char
- f(int x), where the x will be narrowed in f (i.e. the caller will pass
- an int, and the receiver will narrow it), whereas g is prototyped char
- g(char x), i.e. the caller will pass a char.
-
- And, all declarations, including definitions, are seen only ``down
- wind''.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-